/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.asset.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import top.continew.admin.asset.model.entity.ConsumableTracksDO;
import top.continew.admin.asset.service.ConsumableTracksService;
import top.continew.starter.extension.crud.enums.Api;

import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.web.bind.annotation.*;

import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.admin.common.controller.BaseController;
import top.continew.admin.asset.model.query.ConsumableRecordsQuery;
import top.continew.admin.asset.model.req.ConsumableRecordsReq;
import top.continew.admin.asset.model.resp.ConsumableRecordsDetailResp;
import top.continew.admin.asset.model.resp.ConsumableRecordsResp;
import top.continew.admin.asset.service.ConsumableRecordsService;
import top.continew.starter.extension.crud.model.resp.IdResp;

/**
 * 资产-耗材-清单管理 API
 *
 * @author CharlieYan
 * @since 2025/05/08 09:12
 */
@Tag(name = "资产管理-耗材-清单 API")
@RestController
@Validated
@RequiredArgsConstructor
@CrudRequestMapping(value = "/asset/consumable/records", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE,
    Api.EXPORT})
public class ConsumableRecordsController extends BaseController<ConsumableRecordsService, ConsumableRecordsResp, ConsumableRecordsDetailResp, ConsumableRecordsQuery, ConsumableRecordsReq> {

    private final ConsumableTracksService consumableTracksService;

    @Operation(summary = "耗材-入库", description = "耗材-入库")
    @SaCheckPermission("asset:consumable:records:inbound")
    @PostMapping(value = "/inbound")
    public IdResp<Long> inbound(@RequestBody ConsumableTracksDO consumableTracksDO) {
        return new IdResp(consumableTracksService.consumableInbound(consumableTracksDO));
    }

    @Operation(summary = "耗材-领用", description = "耗材-领用")
    @SaCheckPermission("asset:consumable:records:usage")
    @PostMapping(value = "/usage")
    public IdResp<Long> usage(@RequestBody ConsumableTracksDO consumableTracksDO) {
        return new IdResp(consumableTracksService.consumableUsage(consumableTracksDO));
    }

}